package com.yangxd.auth;

import com.yangxd.response.Result;
import com.yangxd.response.ResultCode;
import org.springframework.security.web.session.SessionInformationExpiredEvent;
import org.springframework.security.web.session.SessionInformationExpiredStrategy;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import java.io.IOException;

/**
 * 账户被踢下线处理
 * @Author: yangxudong
 * @Date: 2021/4/23 14:39
 * @Version 1.0
 */
@Component
public class MyExpiredSessionStrategy extends JSONAuthentication implements SessionInformationExpiredStrategy {
    @Override
    public void onExpiredSessionDetected(SessionInformationExpiredEvent sessionInformationExpiredEvent) throws IOException, ServletException {
        Result result = Result.error(ResultCode.USER_ACCOUNT_USE_BY_OTHERS);
        this.WriteJSON(sessionInformationExpiredEvent.getRequest(),sessionInformationExpiredEvent.getResponse(),result);
    }
}
